<template>
  <div id="goods">
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 输入框 -->
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="questOrder.query"
            class="input-with-select"
            clearable
            @clear="getOrder"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrder"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="getOrderList" style="width: 100%" border stripe>
        <el-table-column type="index" label="#" width="48"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="250"
        ></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="207"
        ></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="204">
          <template #default="scope">
            <el-tag type="danger" effect="dark" v-if="scope.row.pay_status == 0"
              >未付款</el-tag
            >
            <el-tag effect="dark" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="204">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="204">
          <template #default="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template #default="scope">
            <el-tooltip
              class="item"
              effect="dark"
              content="修改订单地址"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="primary"
                class="btnEditor"
                icon="el-icon-edit"
                @click="editorVisible = true"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="物流信息"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="success"
                class="btnEditor"
                icon="el-icon-location-outline"
                @click="progressInfo"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="questOrder.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editorVisible"
      width="50%"
      @close="addressClose"
    >
      <el-form
        ref="addressFormRef"
        :rules="addressFormRules"
        :model="addressForm"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader :options="cityOptions" v-model="addressForm.address1">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editorVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressBtns">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流对话框 -->
    <el-dialog title="物流进度" :visible.sync="infoVisible" width="50%">
      <span slot="footer" class="dialog-footer">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :icon="activity.icon"
            :type="activity.type"
            :color="activity.color"
            :size="activity.size"
            :timestamp="activity.timestamp"
          >
            {{ activity.content }}
          </el-timeline-item>
        </el-timeline>
        <el-button @click="infoVisible = false">取 消</el-button>
        <el-button type="primary" @click="infoVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityOptions from '../assets/js/city_option.js'
export default {
  name: 'orders',
  data() {
    return {
      // 订单数据
      getOrderList: [],
      // 订单页
      questOrder: {
        query: '',
        pagenum: 1,
        pagesize: 5,
      },
      // 总页数
      total: 0,
      // 修该地址
      addressForm: {
        address1: [],
        address2: '',
      },
      editorVisible: false,
      // 表单验证
      addressFormRules: {
        address1: [
          { required: true, message: '请选择收货地址', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      cityOptions: cityOptions,
      // 物流信息
      infoVisible: false,
      activities: [{
          content: '已签收,签收人是（快递已送代理点如有问题请联系11053685196）先生/女士，如有疑问请联系派件员寒亭魏飞飞(11053685196、0530-18194261)，如您未收到此快递，请拨打投诉电话：0530--17366376，感谢使用申通快递，期待再次为您服务',
          timestamp: '2021-12-15 20:46',
          size: 'large',
          type: 'primary',
          icon: 'el-icon-location',
          color:'green'
        }, {
          content: '山东潍坊寒亭营业厅-寒亭魏飞飞(11053685196,0530-18194261)-派件中',
          timestamp: '2021-12-14 17:46',
        }, {
          content: '已到达-山东潍坊寒亭营业厅',
          timestamp: '2021-12-14 10:06',
          size: 'large'
        }, {
          content: '山东潍坊转运中心-已发往-山东潍坊寒亭公司',
          timestamp: '2021-12-13 15:26'
        },{
          content: '安徽合肥转运中心-已发往-山东临沂转运中心',
          timestamp: '2021-12-13 07:30'
        },{
          content: '安徽利辛公司-已发往-安徽阜阳转运中心',
          timestamp: '2021-12-12 00:00'
        },{
          content: '安徽利辛公司-城南吴彦祖-已收件',
          timestamp: '2021-12-11 08:00'
        }]
    }
  },
  created() {
    this.getOrder()
  },
  methods: {
    async getOrder() {
      const { data: res } = await this.$http.get('orders', {
        params: this.questOrder,
      })
      if (res.meta.status !== 200) return
      // 订单数据
      this.getOrderList = res.data.goods
      // 总页数
      this.total = res.data.total
      console.log(this.getOrderList)
    },
    // 每页几条
    handleSizeChange(newPagesize) {
      this.questOrder.pagesize = newPagesize
      this.getOrder()
    },
    // 当前第几页
    handleCurrentChange(newPagenum) {
      this.questOrder.pagenum = newPagenum
      this.getOrder()
    },
    // 确定修该地址
    addressBtns() {
      this.$refs.addressFormRef.validate((vail) => {
        if (!vail) return this.$message.error('表单验证失败')
        this.$message.success('地址修该成功')
      })
    },
    // 关闭修该地址对话框
    addressClose() {
      this.$refs.addressFormRef.resetFields()
    },
    // 查看物流信息
    progressInfo() {
      // const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      // if(res.meta.status !== 200) return this.$message.error(res.meta.message)
      // this.$message.success(res.meta.message)

      this.infoVisible = true
    },
  },
}
</script>

<style lang="less" scoped>
.el-card {
  margin-top: 15px;
  box-shadow: none !important;
}
.el-table {
  margin-top: 15px;
  font-size: 12px;
}
.btnEditor {
  padding: 5px 15px;
  font-size: 12px;
}
.el-tag {
  font-size: 12px;
  height: 20px;
  line-height: 19px;
  padding: 0 5px;
}
.el-pagination {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
.el-timeline{
  text-align: left;
}
/deep/ .el-dialog__body{
  padding: 0;
}
</style>